package com.flyduck.mall.pms.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.flyduck.mall.pms.admin.service.AdminSpecificationService;
import com.flyduck.mall.pms.admin.vo.*;
import com.flyduck.ss.common.core.domain.R;
import com.flyduck.mall.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * <p>
 * SysMenuController
 * </p>
 *
 * @author flyduck
 * @since 2024-06-03
 */
@RestController
@RequestMapping("/admin/specification")
public class AdminSpecificationController extends BaseController {

    @Resource
    private AdminSpecificationService sysSpecificationService;

    @GetMapping("/getSpecificationPage")
    public R<Page<AdminSpecificationRespVO>> getSpecificationPage(AdminSpecificationQueryReqVO sysSpecificationQueryReqVO){
        Page<AdminSpecificationRespVO> adminSpecificationRespVOPage = sysSpecificationService.getSpecificationPage(getPage(),sysSpecificationQueryReqVO);
        return R.ok(adminSpecificationRespVOPage);
    }

    @GetMapping("/getSpecificationDetailsById/{id}")
    public R<AdminSpecificationDetailsRespVO> getSpecificationDetailsById(@PathVariable("id") Long id){
        AdminSpecificationDetailsRespVO sysSpecificationDetailsRespVO = sysSpecificationService.getSpecificationDetailsById(id);
        return R.ok(sysSpecificationDetailsRespVO);
    }

    @PostMapping("/saveSpecification")
    public R<Void> saveSpecification(@Validated @RequestBody AdminSpecificationSaveReqVO adminSpecificationSaveReqVO){
        sysSpecificationService.saveSpecification(adminSpecificationSaveReqVO);
        return R.ok();
    }

    @PostMapping("/updateSpecification")
    public R<Void> updateSpecification(@Validated @RequestBody AdminSpecificationUpdateReqVO adminSpecificationUpdateReqVO){
        sysSpecificationService.updateSpecification(adminSpecificationUpdateReqVO);
        return R.ok();
    }

    @PostMapping("/batchDeleteByIds")
    public R<Void> batchDeleteByIds(@RequestBody Long[] ids){
        sysSpecificationService.batchDeleteByIds(Arrays.asList(ids));
        return R.ok();
    }


}
